package com.mysteel.order.controller;

import com.mysteel.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * ProjectName: mail
 * ClassName: RabbitMqController
 * Description:
 * date: 2021/03/17/017 19:48
 *
 * @author xiaochao
 */
@RestController
public class RabbitMqController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMessage")
    public String sendMessageToMq(Integer messageNum){
        if (messageNum == null){
            messageNum = 10;
        }
        for (int i = 0; i< messageNum;i++){
            if (i % 2 == 0){
                OrderReturnReasonEntity reasonEntity = new OrderReturnReasonEntity();
                reasonEntity.setId(996L);
                reasonEntity.setCreateTime(new Date());
                reasonEntity.setName("微雨");
                reasonEntity.setStatus(i);
                reasonEntity.setSort(i);
                // 如果发送的对象，则默认会以JDK序列化的方式将消息发出，故对象必须实现序列化接口
                rabbitTemplate.convertAndSend("hello.java.direct.exchange","hello.java",reasonEntity,new CorrelationData(UUID.randomUUID().toString()));
            }else {
                rabbitTemplate.convertAndSend("hello.java.direct.exchange","hello.java","蛾儿雪柳黄金缕。笑语盈盈暗香去。众里寻他千百度。蓦然回首，那人却在，灯火阑珊处。",new CorrelationData(UUID.randomUUID().toString()));
            }

        }
        return "ok";
    }
}
